﻿/*!
* 在这之前，必须导入jquery
*/

var actionId = 0;
var start;
var end;
window.onload = function () {
    var para = window.location.href;
    para = para.substr(para.indexOf('?') + 1);
    start = new Date(); //start是用户进入页面时间
    $.ajax({
        url: "/web/Customer/Ashx/action.ashx?mode=onload",
        type: "post",
        data: {
            ActionType: "Browse",
            Referrer: document.referrer,
            RawUrl: window.location.href,
            Params: para,
            url: window.location.href
        },
        success: function (msg) {
            actionId = msg;
            BodyUnload();
            setInterval("BodyUnload()", 3000);
        }
    });
}

window.onbeforeunload = function () {
    BodyUnload();
}
window.onunload == function () {
    BodyUnload();
}

function BodyUnload() {
    end = new Date(); //用户退出时间  
    state = parseInt((end.getTime() - start.getTime()) / 1000); //停留时间=退出时间-开始时间
    if (state != 0)
        $.ajax({
            url: "/web/Customer/Ashx/action.ashx?mode=unload",
            data: {
                id: actionId,
                time: state
            }
        });
}